home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 3 / Gekikoh Dennoh Club Vol. 3 (Japan).7z / Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin / cone / mi506dc / pzau.c < prev    next >
C/C++ Source or Header  |  1998-02-19  |  4KB  |  213 lines

  1. /*
  2.     パワーザウルスのバックアップイメージからデジカメデータを抽出する
  3.  
  4.     by 電魔団\shoryu 1998
  5. */
  6.  
  7.  
  8. #include    <stdio.h>
  9. #include    <doslib.h>
  10. #include    <io.h>
  11.  
  12.  
  13. int    startPos[1024];        //max=1/16VGA normal 438
  14.                     //min=VGA fine 36
  15.  
  16. char    tarDrv[3]="P:";            //@:
  17. char    tarName[256]="\\__ZAURUS\\PAINT1.BOX";    //ファイル名は固定でよかろう
  18. char    *tarBuf;
  19.  
  20.  
  21. /*
  22.     JFIFのヘッダサーチ&ライト
  23. */
  24. int    main(argc,argv)
  25. int    argc;
  26. char    *argv[];
  27. {
  28.     FILE    *fp,*ofp;
  29.     char    *fileName,fileNameBuf[256];
  30.     int    len,st;
  31.     int    pos,count,mcount;
  32.     
  33.     if( Init(argc,argv)<0 ){
  34.         goto quick_exit;
  35.     }
  36.  
  37.  
  38.     fileName=fileNameBuf;
  39.     strcpy(fileName,tarDrv);
  40.     strcat(fileName,tarName);
  41.     fp=fopen(fileName,"rb");
  42.     if( fp==NULL ){
  43.         printf("open err:%s\n",fileName);
  44.         goto quick_exit;
  45.     }
  46.     len=filelength(fileno(fp));
  47.     tarBuf=MALLOC(len);
  48.     if( (int)tarBuf<0 ){        //オンメモリで実行可能か?
  49. //        printf("メモリ不足");
  50.         fclose(fp);        //いったんファイルを閉じて、
  51.         main2(argc,argv);    //少メモリ版実行
  52.         goto quick_exit;
  53.     }
  54.     
  55.     printf("フォトメモリーデータ読み込み中…\n");
  56.     fread(tarBuf,sizeof(char),len,fp);
  57.     fclose(fp);
  58.     
  59.     printf("解析中…\n");    //動けばよしとす
  60.     count=0;
  61.     startPos[count++]=0;
  62.     for( pos=0;pos<len-4;pos++ ){
  63.         if( tarBuf[pos]=='J' ){
  64.             if( tarBuf[pos+1]=='F' &&tarBuf[pos+2]=='I' &&tarBuf[pos+3]=='F' ){
  65. /**/                printf("\x0d%d",pos);
  66.                 startPos[count++]=pos;
  67.             }
  68.         }
  69.     }
  70.     startPos[count]=len;
  71.     mcount=count;
  72.  
  73.     for( count=1;count<mcount;count++ ){
  74.  
  75.         sprintf(fileName,"PZAU%04d.JPG",count);
  76. /**/        printf("\x0d%s",fileName);
  77.         ofp=fopen(fileName,"wb");
  78.  
  79.         //JPEGへっだ部書き込み
  80.         st=0;
  81.         len=startPos[1]-4;
  82.         fwrite(tarBuf+st,sizeof(char),len,ofp);
  83.  
  84.         //JPEGデータ部書き込み
  85.         st=startPos[count]-4;
  86.         len=startPos[count+1]-startPos[count]+1;
  87.         fwrite(tarBuf+st,sizeof(char),len,ofp);
  88.  
  89.         fclose(ofp);
  90.  
  91.     }
  92.     printf("\n");
  93.  
  94. quick_exit:
  95.     ;
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /*
  103.     少メモリ
  104. */
  105. int    main2(argc,argv)
  106. int    argc;
  107. char    *argv[];
  108. {
  109.     FILE    *fp,*ofp;
  110.     char    *fileName,fileNameBuf[256];
  111.     int    len,st;
  112.     int    pos,lpos,count,mcount;
  113.     
  114.     fileName=fileNameBuf;
  115.     strcpy(fileName,tarDrv);
  116.     strcat(fileName,tarName);
  117.     fp=fopen(fileName,"rb");
  118.     if( fp==NULL ){
  119.         printf("open err:%s\n",fileName);
  120.         goto quick_exit;
  121.     }
  122.     len=filelength(fileno(fp));
  123.     tarBuf=MALLOC(256*1024);    //てきとーにワークを確保:256Kあればいいでしょ
  124.     if( (int)tarBuf<0 ){
  125.         printf("err:メモリ不足\n");
  126.         goto quick_exit;
  127.     }
  128.     printf("解析中…\n");
  129.     count=0;
  130.     startPos[count++]=0;
  131.     for( pos=0;pos<len-4;pos+=(32*1024-16) ){
  132.         fseek(fp,pos,SEEK_SET);
  133.         fread(tarBuf,sizeof(char),32*1024,fp);    //読み込みは32K
  134.         for( lpos=0;lpos<32*1024-4;lpos++ ){
  135.             if( tarBuf[lpos]=='J' ){
  136.                 if( tarBuf[lpos+1]=='F' &&tarBuf[lpos+2]=='I' &&tarBuf[lpos+3]=='F' ){
  137.                     printf("\x0d%d",pos+lpos);
  138.                     startPos[count++]=pos+lpos;
  139.                 }
  140.             }
  141.         }
  142.     }
  143.     startPos[count]=len;
  144.     mcount=count;
  145.     
  146.  
  147.     for( count=1;count<mcount;count++ ){
  148.  
  149.         sprintf(fileName,"PZAU%04d.jpg",count);
  150.         ofp=fopen(fileName,"wb");
  151. /**/        printf("\x0d%s",fileName);
  152.         
  153.         //JPEGへっだ書き込み
  154.         st=0;
  155.         len=startPos[1]-4;
  156.         fseek(fp,st,SEEK_SET);
  157.         fread(tarBuf,sizeof(char),len,fp);
  158.         fwrite(tarBuf,sizeof(char),len,ofp);
  159.  
  160.         //JPEGデータ書き込み
  161.         st=startPos[count]-4;
  162.         len=startPos[count+1]-startPos[count]+1;
  163.         fseek(fp,st,SEEK_SET);
  164.         fread(tarBuf,sizeof(char),len,fp);
  165.         fwrite(tarBuf,sizeof(char),len,ofp);
  166.  
  167.         fclose(ofp);
  168.  
  169.     }
  170.  
  171.     fclose(fp);
  172.     printf("\n");
  173.  
  174. quick_exit:
  175.     exit();
  176. }
  177.  
  178.  
  179.  
  180.  
  181. /*
  182.     エラー:0未満
  183.  
  184. */
  185. int    Init(argc,argv)
  186. int    argc;
  187. char    *argv[];
  188. {
  189.     int    res=0;
  190.  
  191.     if( argc!=2 ){
  192.         printf(
  193.         "X680x0 PowerZAURUS JPEGファイル変換ユーティリティー\n"
  194.         "PowerZAURUS のフォトメモリーデータをJPEGファイルに変換し、\n"
  195.         "カレントにPZAU????.JPGとして出力します\n"
  196.         "使用方法:@>PZAU drive\n"
  197.         " drive :PCカードドライブ(P:などで指定)\n"
  198.         );
  199.         res=-1;
  200.     }
  201.     else{
  202.         strcpy(tarDrv,argv[1]);
  203.     }
  204.  
  205.     return(res);
  206. }
  207.  
  208.  
  209.  
  210.  
  211. /* [ EOF ] */
  212.  
  213.